
import javax.swing.*;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;


public class Login extends JFrame {

    public Login(){
        super("图书管理系统");
        this.setSize(1920,1080);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        ImageIcon img = new ImageIcon("images/样图.png");//这是背景图片
        JLabel imgLabel = new JLabel(img);//将背景图放在标签里。
        this.getLayeredPane().add(imgLabel, new Integer(Integer.MIN_VALUE));//背景标签添加
        imgLabel.setBounds(0,0,img.getIconWidth(), img.getIconHeight());//设置背景标签的位置
        Container cp=this.getContentPane();
        cp.setLayout(null);
        ((JPanel)cp).setOpaque(false); //注意这里，将内容面板设为透明


        JTextField userName = new JTextField("");
        JPasswordField password = new JPasswordField("");
        userName.setBounds(1360, 385, 240, 50);
        password.setBounds(1360, 522, 240, 50);
        userName.setFont(new Font("Arial", Font.PLAIN, 26));
        password.setFont(new Font("Arial", Font.PLAIN, 26));
        userName.setBorder(new LineBorder(null,0));
        password.setBorder(new LineBorder(null,0));
        userName.setOpaque(false);
        password.setOpaque(false);

        JLabel b1 = new JLabel(new ImageIcon("images/登录.png"));
        b1.setBounds(1210, 690, 395, 50);
        JLabel admin = new JLabel(new ImageIcon("images/忘记密码.png"));
        JLabel regist = new JLabel(new ImageIcon("images/注册.png"));
        admin.setBounds(1178, 810, 200, 50);
        regist.setBounds(1475, 810, 200, 50);

        cp.add(userName);
        cp.add(password);
        cp.add(b1);
        cp.add(admin);
        cp.add(regist);

        this.setVisible(true);

        b1.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                String password1 = String.valueOf(password.getPassword());
                if(userName.getText().equals("yuruiqiao")&&password1.equals("15162823853")){
                    ReaderList readerList = new ReaderList();
                    readerList.setVisible(true);
                    setVisible(false);//将登录页关闭
                }
                else{
                    JOptionPane.showMessageDialog(null,"账号或者密码错误" ,
                            "提示信息", JOptionPane.ERROR_MESSAGE);
                }

            }

            @Override
            public void mousePressed(MouseEvent e) {

            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {
                b1.setIcon(new ImageIcon("images/登录1.png"));
            }

            @Override
            public void mouseExited(MouseEvent e) {
                b1.setIcon(new ImageIcon("images/登录.png"));
            }
        });
        admin.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {

            }

            @Override
            public void mousePressed(MouseEvent e) {
                admin.setIcon(new ImageIcon("images/忘记密码1.png"));
            }

            @Override
            public void mouseReleased(MouseEvent e) {

            }

            @Override
            public void mouseEntered(MouseEvent e) {
                admin.setIcon(new ImageIcon("images/忘记密码1.png"));
            }

            @Override
            public void mouseExited(MouseEvent e) {
                admin.setIcon(new ImageIcon("images/忘记密码.png"));
            }
        });
        regist.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                register regist1 = new register();
                regist1.setVisible(true);
            }

            @Override
            public void mousePressed(MouseEvent e) {
                regist.setIcon(new ImageIcon("images/注册.png"));
            }

            @Override
            public void mouseReleased(MouseEvent e) {
                regist.setIcon(new ImageIcon("images/注册1.png"));
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                regist.setIcon(new ImageIcon("images/注册1.png"));
            }

            @Override
            public void mouseExited(MouseEvent e) {
                regist.setIcon(new ImageIcon("images/注册.png"));
            }
        });

        password.addKeyListener(new KeyListener() {
            @Override
            public void keyTyped(KeyEvent e) {
                if(e.getKeyChar() == KeyEvent.VK_ENTER){
                    String password1 = String.valueOf(password.getPassword());
                        if(userName.getText().equals("yuruiqiao")&&password1.equals("15162823853")){
                            ReaderList readerList = new ReaderList();
                            readerList.setVisible(true);
                            setVisible(false);//将登录页关闭
                    }
                    else{
                        JOptionPane.showMessageDialog(null,"账号或者密码错误" ,
                                "提示信息", JOptionPane.ERROR_MESSAGE);
                    }
                }
            }

            @Override
            public void keyPressed(KeyEvent e) {

            }

            @Override
            public void keyReleased(KeyEvent e) {

            }
        });

    }

    public static void main(String[] args) {
        Login login = new Login();
    }
}
